import {createSlice} from '@reduxjs/toolkit';

const counterStore = createSlice({
    name:'counter',
    // 初始化state
    initialState:{
        count: 0
    },
    //修改状态方法 同步方法 支持直接修改
    reducers: {
        inscrement(state){
            state.count++
        },
        decrement(state){
            state.count--
        },
        addTonum(state,action){
            console.log(state ,'action',state.count)
            state.count = action.payload;  // payload  是固定属性
        }
    }
}) 

// 结构出来 actionCreater 函数
const {inscrement ,decrement ,addTonum} = counterStore.actions;
//获取reducer
const reducer = counterStore.reducer;
//以按需导出的方式导出 actionCreater
export {inscrement ,decrement ,addTonum};
//以默认导出方式导出
export default reducer;